<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../JS/react.development.js"></script>
    <script src="../../JS/react-dom.development.js"></script>
    <script src="../../JS/babel.min.js"></script>
</head>
<body>
    <div id="root"></div>
    <script type="text/babel">
        class Increase extends React.Component {
            constructor(props) {
                super(props);
                this.state = {iNum: 10};
            }

            // 通过setState方法来改变state里面的值
            // setState里面可以传一个对象 也可以传一个函数 函数需要返回值
            fnAdd() {
                // this.setState({
                //     iNum: this.state.iNum + 1
                // })

                // pervState指的时state最新的值
                this.setState(pervState =>
                    ({iNum: pervState.iNum + 1})
                )
            }

            render() {
                return(
                    <div>
                        <p>{this.state.iNum}</p>
                        <input type="button" value="递增" onClick={this.fnAdd.bind(this)}/>
                    </div>
                )
            }
        }
        ReactDOM.render(<Increase />, document.getElementById('root'));
    </script>
</body>
</html>